package com.gopay.common.gateway.dao.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.domain.fund.FundGopayAgreementEntity;
import com.gopay.common.gateway.dao.PgFundAgreementInfoQueryDao;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Repository("pgFundAgreementInfoQueryDao")
public class PgFundAgreementInfoQueryDaoImpl extends BaseDAOImpl<FundGopayAgreementEntity, Serializable> implements
        PgFundAgreementInfoQueryDao {

    @Override
    public List getList(String today,String yesterday) {
        StringBuilder sql = new StringBuilder("from FundGopayAgreementEntity where  lastUpdTs>=TO_DATE(:yesterday,'yyyymmddHH24miss') and lastUpdTs<=TO_DATE(:today,'yyyymmddHH24miss') and STATUS = (:STATUS)");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("yesterday",yesterday);
        map.put("today",today);
        map.put("STATUS",'1');

        List<FundGopayAgreementEntity> byHql = findByHql(sql.toString(),map);
        if (byHql.size() > 0) {
            return byHql;
        }
        return null;
    }

    @Override
    public Map<String,List<FundGopayAgreementEntity>> getList(String today, String yesterday, List<String> merchantIds) {
        Map<String,List<FundGopayAgreementEntity>> mapList = new HashMap<String, List<FundGopayAgreementEntity>>();
        for(String merchantId:merchantIds) {
            StringBuilder sql = new StringBuilder("from FundGopayAgreementEntity where  lastUpdTs>=TO_DATE(:yesterday,'yyyymmddHH24miss') and lastUpdTs<=TO_DATE(:today,'yyyymmddHH24miss') and STATUS = (:STATUS)");
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("yesterday", yesterday);
            map.put("today", today);
            map.put("STATUS", '1');

            List<FundGopayAgreementEntity> byHql = findByHql(sql.toString(), map);
            mapList.put(merchantId,byHql);
        }
        if (mapList!=null && mapList.size() > 0) {
            return mapList;
        }
        return null;
    }

}